package com.lvy.hczn.transmit.controller;

import com.lvy.hczn.front.common.core.domain.AjaxResult;
import com.lvy.hczn.front.common.exception.UtilException;
import com.lvy.hczn.mq.rocket.ParamInfo;
import com.lvy.hczn.transmit.domain.dto.cteck.TransferTask;
import com.lvy.hczn.transmit.service.TTransferService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RequestMapping("/api/dt/transfer/")
@RestController
@Slf4j
public class TTransferController {

    @Autowired
    private TTransferService transferService;

    @ApiOperation(value = "调拨任务推送，接口设计过于复杂，调拨分拣接口只需要告知哪个仓库要分拣什么商品，怎么分拣即可，什么总仓调前置仓，前置仓调总仓，应调拨运输接口告知，重构数据结构必须改", notes = "调拨任务推送，接口设计过于复杂，调拨分拣接口只需要告知哪个仓库要分拣什么商品，怎么分拣即可，什么总仓调前置仓，前置仓调总仓，应调拨运输接口告知，重构数据结构必须改")
    @PostMapping("batch")
    public AjaxResult syncTransferFromPlatform(HttpServletRequest request, @RequestBody ParamInfo info) {
        try {
            transferService.syncTransferFromPlatform(request, info);
            return AjaxResult.success();
        } catch (Exception e) {
            if (e instanceof UtilException) {
                return AjaxResult.error(e.getMessage());
            } else {
                log.error("syncTransferFromPlatform同步异常：", e);
                return AjaxResult.error("系统异常");
            }
        }
    }
}
